package com.study.model.jdao;

import java.util.List;
import java.util.Map;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import com.study.model.pojo.Rights;

public interface RightsJdao extends CrudRepository<Rights,Integer>{

	@Query("from Rights r where  r.deptno=?1")
	public List<Rights> findAllrightBydt(int deptno);
	
	/**
	 * 查找员工在这个部门没有的权限*/
	@Query("SELECT r FROM Rights r  WHERE r.deptno = ?1 AND r.rid NOT IN(SELECT r.rid from Empwithright em, r WHERE r.rid=em.rid AND em.eid= ?2 AND r.deptno= ?1)")
	public List<Rights> notthisright(int deptno,int eid);
	
	@Query("SELECT r.rname FROM Rights r,Empwithright em WHERE  r.rid=em.rid AND em.eid=?2 AND r.deptno=?1")
	public String rightname(int deptno,int eid);
	
	/**
	 * 查找员工在部门下拥有的权限*/
	@Query("SELECT r FROM Rights r,Empwithright em WHERE r.rid=em.rid AND em.eid=?1 AND r.deptno=?2")
	public List<Rights> rightnamex(int eid,int deptno);
	
	/**
	 * 查找员工在部门下拥有的权限*/
	@Query("SELECT r.rname FROM Rights r,Empwithright em WHERE r.rid=em.rid AND em.eid=?1 AND r.deptno=?2")
	public List<String> rightnamey(int eid,int deptno);
}
